var $ = require("../../utils/Ajax.js");
Page({
  data: {
    // 财富等级
    Wealth: [],
    WealthValue: "根据财富等级设置",

    // 智慧等级
    Wisdom: [],
    WisdomValue: "根据智慧等级设置",
  },

  onLoad: function (options) {
    var UserSet = wx.getStorageSync('UserInfor');
    var shieldIntelligenceLevel = UserSet.user_set.shieldIntelligenceLevel;
    if (shieldIntelligenceLevel) {
      this.setData({
        WealthValue: "根据财富等级设置",
        WisdomValue: "允许" + shieldIntelligenceLevel + "级以上的人打招呼"
      })
    }
    var shieldWealthLevel = UserSet.user_set.shieldWealthLevel;
    if (shieldWealthLevel) {
      this.setData({
        WealthValue: "允许" + shieldWealthLevel + "级以上的人打招呼",
        WisdomValue: "根据智慧等级设置"
      })
    }
    var that = this;
    wx.setNavigationBarTitle({
      title: "交友设置"
    })
    $.Ajax("api/userLevel","GET",{},function(res){
      if(res.s){
        that.setData({
          Wealth: res.d.level0,
          Wisdom: res.d.level1
        })
      }else{
        wx.showToast({
          title: res.m,
          icon: 'none',
          duration: 3000
        });
      }
    })
  },

  // 财富等级
  Wealth: function (e) {
    var that = this;
    var Index = e.detail.value;
    var Wealth = this.data.Wealth[Index].level;
    $.Ajax("api/userSet", "POST", {
      shieldWealthLevel: Wealth,
      shieldIntelligenceLevel: 0
    }, function (res) {
      that.setData({
        WealthValue: "允许" + Wealth + "级以上的人打招呼",
        WisdomValue: "根据智慧等级设置"
      })
    });
  },

  // 智慧等级
  Wisdom: function (e) {
    var that = this;
    var Index = e.detail.value;
    var Wisdom = this.data.Wisdom[Index].level;
    $.Ajax("api/userSet", "POST", {
      shieldWealthLevel: 0,
      shieldIntelligenceLevel: Wisdom
    }, function (res) {
      that.setData({
        WealthValue: "根据财富等级设置",
        WisdomValue: "允许" + Wisdom + "级以上的人打招呼"
      })
    });
  }
})